package com.example.test;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.example.test.db.DBOpenHelper;

public class MainActivity extends AppCompatActivity{
   private Button btnRegister,btnLogin;
   private EditText userPhone,userPwd,userName;
   private String phone,pwd;
//   private String name="1";
//    private String paw="1";
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
//        init();
        userName = findViewById(R.id.userName);
        userPwd = findViewById(R.id.userPwd);
        btnLogin =findViewById(R.id.btnLogin);
        btnLogin.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (new DBOpenHelper(view.getContext()).login(userName.getText().toString(),userPwd.getText().toString())){
                    Toast.makeText(MainActivity.this,"这事成了！！",Toast.LENGTH_LONG).show();
                    Intent intent = new Intent(MainActivity.this, HomeActivity.class);
                    startActivity(intent);
                }else {
                    Toast.makeText(MainActivity.this,"这事寄了！！",Toast.LENGTH_LONG).show();
                }

            }
        });
        btnRegister = findViewById(R.id.btnRegister);
        btnRegister.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(MainActivity.this,RegisterActivity.class);
                startActivity(intent);
            }
        });
    }
//    public void init(){
//        btnRegister = findViewById(R.id.btnRegister);
//        btnRegister.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                Intent intent = new Intent(MainActivity.this,RegisterActivity.class);
//                startActivity(intent);
//            }
//        });
//        btnLogin = findViewById(R.id.btnLogin);
//        userPhone = findViewById(R.id.userPhone);
//        userPwd = findViewById(R.id.userPwd);
//        btnLogin =findViewById(R.id.btnLogin);
//        btnLogin.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                phone=userPhone.getText().toString();
//                pwd=userPwd.getText().toString();
//                if(!phone.equals("")){
//                    if (phone.equals(name)){
//                        if (pwd.equals(paw)){
//                            Intent intent=new Intent();
//                            intent.setClass(MainActivity.this,HomeActivity.class);
//                            startActivity(intent);
//                        }else {
//                            Toast.makeText(MainActivity.this,"密码错误",Toast.LENGTH_SHORT).show();
//                        }
//                    }else {
//                        Toast.makeText(MainActivity.this,"账号不存在",Toast.LENGTH_SHORT).show();
//                    }
//                }else {
//                    Toast.makeText(MainActivity.this,"请输入手机号",Toast.LENGTH_SHORT).show();
//
//                }
//            }
//        });
//
//
//
//    }11


}